package com.jgsu.farm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jgsu.farm.entity.Inquiry;
import com.jgsu.farm.entity.MatchImage;
import com.jgsu.farm.entity.Question;
import com.jgsu.farm.exception.DataNotExistException;
import com.jgsu.farm.mapper.InquiryMapper;
import com.jgsu.farm.mapper.SpectralMapper;
import com.jgsu.farm.service.InquiryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InquiryServiceImpl implements InquiryService {
    @Autowired
    InquiryMapper inquiryMapper;
    @Autowired
    SpectralMapper spectralMapper;


    @Override
    public void add(Inquiry inquiry) {

    }

    @Override
    public void delete(Integer inquiryid) {
        // 1. 先查询数据库中是否存在该数据
        int i = inquiryMapper.deleteByPrimaryKey(inquiryid);
        if (i == 0) {
            throw new DataNotExistException("400", "数据库中不存在该数据，删除异常");
        }

    }


    @Override
    public PageInfo<Inquiry> selectAll(int page, int pagesize) {
        PageHelper.startPage(page, pagesize);
        List<Inquiry> inquiries = inquiryMapper.selectAll();
        PageInfo<Inquiry> pageInfoInquiryList = new PageInfo<Inquiry>(inquiries);
        return pageInfoInquiryList;
    }

    @Override
    public void update(Inquiry inquiry) {

    }
}

